<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>计算属性,方法,侦听器</title>
    <script src="../../vue.js"></script>
</head>

<body>
    <div id="app">
        {{firstName}}
        {{lastName}}
    </div>

    <script>

        // 侦听器跟计算属性一样也都是有缓存的

        const app = new Vue({ // 侦听器
            el: '#app',
            data: { // 2. data里面的属性就是侦听器要侦听的内容
                firstName: 'haha',
                lastName: 'hehe'
            },
            watch: { // 1. 使用侦听器, 当要侦听的内容发生改变的时候就会触发事件
                firstName: function () { // 3. 侦听器要侦听的事件1
                    console.log('侦听到firstName有变动');
                    
                    return this.firstName + ' ' + this.lastName;
                },
                lastName: function () { // 4. 侦听器要侦听的事件2
                    console.log('侦听到lastName有变动');

                    return this.firstName + ' ' + this.lastName;
                }
            },
        })
    </script>
</body>

</html>